package com.woniu.util;

import org.springframework.stereotype.Component;

import java.lang.reflect.Field;
import java.util.Objects;

/**
 * @description:对象工具类
 * @author: my
 * @time: 2021/5/8 14:24
 */
@Component
public class ObjectUtil {

    public boolean checkAllFieldIsNotNull(Object o){
        Class<?> cls = o.getClass();
        Field[] fields = cls.getDeclaredFields();
        try {
            for (Field field : fields) {
                //使私有字段可以被访问
                field.setAccessible(true);
                Object o1 = field.get(o);
                if (Objects.isNull(o1) || "".equals(o1.toString())){
                    return false;
                }
            }
        } catch (IllegalAccessException e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }
}
